{include file='common/head' /}
<body>
<script src="/static/pluring/jq.js"></script>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <input type="hidden" name="id" value="{$data.id|default=''}">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    等级名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="name" required="" autocomplete="off" class="layui-input" value="{$data.name|default=''}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    名称唯一，不能重复
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    等级权重
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="sort" required="" autocomplete="off" class="layui-input" value="{$data.sort|default=0}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    数字越大，表示等级越高，最高99999
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    等级条件:累计业绩
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="level" required="" autocomplete="off" class="layui-input" value="{$data.level|default=0}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    此等级达标金额，取整数
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    等级条件:直推人数
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="direct_push" required="" autocomplete="off" class="layui-input" value="{$data.direct_push|default=0}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    此等级达标直推人数
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    等级条件:团队人数
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="team_num" required="" autocomplete="off" class="layui-input" value="{$data.team_num|default=0}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    此等级达标团队人数
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    自购省
                </label>
                <div class="layui-input-inline">
                    <input type="number" name="purchase" required="" autocomplete="off" class="layui-input" value="{$data.purchase|default=0}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    填写比例，取整数，0-99
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    分享赚
                </label>
                <div class="layui-input-inline">
                    <input type="number" name="share" required="" autocomplete="off" class="layui-input" value="{$data.share|default=0}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    填写比例，取整数，0-99
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    消费团队佣金(直推)
                </label>
                <div class="layui-input-inline">
                    <input type="number" name="team" required="" autocomplete="off" class="layui-input" value="{$data.team|default=0}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    消费团队佣金比例，取整数，0-99
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    消费团队佣金(间推)
                </label>
                <div class="layui-input-inline">
                    <input type="number" name="team_twe" required="" autocomplete="off" class="layui-input" value="{$data.team_twe|default=0}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    消费团队佣金比例，取整数，0-99
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    消费管理津贴
                </label>
                <div class="layui-input-inline">
                    <input type="number" name="manage" required="" autocomplete="off" class="layui-input" value="{$data.manage|default=0}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    消费管理津贴比例，取整数，0-99
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    购物券团队佣金类型
                </label>
                <div class="layui-input-inline">
                    <input type="radio" name="coupon_type" value="1" title="比例" {if condition="$data['coupon_type'] eq 1"}checked{/if}>
                    <input type="radio" name="coupon_type" value="2" title="固定" {if condition="$data['coupon_type'] eq 2"}checked{/if}>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    购物券团队佣金类型，1-比例，2-固定
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    购物券团队佣金(直推)
                </label>
                <div class="layui-input-inline">
                    <input type="number" name="coupon_team" required="" autocomplete="off" class="layui-input" value="{if condition="$data['coupon_type'] == 1"}{$data.coupon_team|default=0}{else/}{$data.coupon_team*10}{/if}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    购物券团队佣金比例，取整数，0-99
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    购物券团队佣金(间推)
                </label>
                <div class="layui-input-inline">
                    <input type="number" name="coupon_team_twe" required="" autocomplete="off" class="layui-input" value="{$data.coupon_team_twe|default=0}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    购物券团队佣金比例，取整数，0-99
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    购物券团队管理津贴
                </label>
                <div class="layui-input-inline">
                    <input type="number" name="coupon_manage" required="" autocomplete="off" class="layui-input" value="{$data.coupon_manage|default=0}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    购物券团队管理津贴比例，取整数，0-99
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    描述说明
                </label>
                <div class="layui-col-md9">
                    <textarea id="textarea" name="desc" placeholder="请输入内容" value="{$data.desc|default=''}" class="layui-textarea"></textarea>
                    <script>
                        setTimeout(function(){
                            document.getElementById("textarea").value = "{$data.desc|default=''}";
                        },250)
                    </script>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    描述说明，文字描述
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="add" lay-submit="">确定保存</button></div>
        </form>
    </div>
</div>
<script>layui.use(['form', 'layer','jquery'],
        function() {
            $ = layui.jquery;
            var form = layui.form,
                    layer = layui.layer;

            //监听提交
            form.on('submit(add)', function(data) {
                $.ajax({
                    url:"{:url('Users/level_edit')}",
                    type: "post",
                    data:data.field,
                    dataType:"json",
                    success:function (res) {
                        if(res.code == 200){
                            layer.alert(res.msg, {icon: 1},function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        }else{
                            layer.alert(res.msg, {icon:2,time:1000});
                        }
                    },
                    error:function(e){
                        layer.alert("网络错误", {icon:5,time:1000});
                    },
                });
                return false;
            });
        });

//添加属性
function attr_add(obj){
    var html = '';
    html += '<tr>';
    html += '<td style="width:90%;">';
    html += '<input type="text" name="desc[]" required="" autocomplete="off" class="layui-input" value="">';
    html += '</td>';
    html += '<td style="width:10%;text-align: center">';
    html += '<a href="javascript:;" onclick="attr_del(this)">';
    html += '<i class="iconfont">&#xe6fe;</i>删除';
    html += '</a>';
    html += '</td>';
    html += '</tr>';

    $(obj).parents("tr").parents('tbody').append(html);
}

//删除属性
function attr_del(obj){
    $(obj).parents("tr").remove();
}

////按钮-进行上传操作--图片阅览
//$('#test1').click(function(){
//    $('#test1s').click();
//})
//
//// 操作成功后的回调
//$('#test1s').change(function(e){
//    var imgBox = e.target;
//    if(imgBox.files[0].size > 1024 * 1024 *2){
//        return layer.msg('失败，文件不得超过2mb',{icon: 5})
//    }
//    var img = getObjectURL(imgBox.files[0]);
//    $('#img').attr('src',img);
//    var data = {image: imgBox.files[0]}
//    var formData = new FormData();
//    formData.append('image', imgBox.files[0]);
//    formData.append('prefix','levelBanner');
//    $.ajax({
//        url:"{:url('admin/uploads/uploadImg')}",
//        type: 'post',
//        async: false,
//        data: formData,
//        dataType: 'json',
//        processData: false,// 告诉jQuery不要去处理发送的数据
//        contentType: false,// 告诉jQuery不要去设置Content-Type请求头
//        beforeSend: function (){ //过程...
//        },
//        success: function (res) {
//            console.log(res.data)
//            if (res.code == 200) {
//                layer.msg('加载成功', {icon: 6})
//                //$('input[name=img_url]').val(HOST_URL +'/' +  res.data.fileName + '/' + (res.data.prefix ? '/' +  res.data.prefix + '/' : '') + res.data.url.replace("\\",'/'))
//                $('input[name=img]').val( (res.data.prefix ? '/' +  res.data.prefix + '/' : '') + res.data.url.replace("\\",'/'))
//            } else {
//                layer.msg(res.msg || '失败，麻烦重新尝试', {icon: 5})
//            }
//        },
//        error:function(){
//            layer.msg( '失败，重新尝试，多次失败后麻烦联系开发人员', {icon: 5})
//        }
//    })
//});
//
////建立一個可存取到該file的url
//function getObjectURL(file) {
//    var url;
//    if (window.createObjectURL != undefined) { // basic
//        url = window.createObjectURL(file);
//    } else if (window.URL != undefined) { // mozilla(firefox)
//        url = window.URL.createObjectURL(file);
//    } else if (window.webkitURL != undefined) { // webkit or chrome
//        url = window.webkitURL.createObjectURL(file);
//    }
//    return url;
//}
</script>
{include file='common/footer' /}